<?php
class TaskAction extends IntesysAction {
	function index(){ 
		if(isMobile()){
			$this->initView();
			$TicketDB=D('Task');
			$TicketDB->filter($this->view);
		}
		
       //获取 筛选或添加 所需型，部门，所有员工等数据
       $staff=D('Member')->getallgroupmember2();
       $this->assign('grouplist',D('Member_group')->getGroup());
	   $this->assign('ruletypelist',D('Integral_ruletype')->getRuletype(0));
       $this->assign('memberlist',$staff);
	   $this->display();   
	}
	public function test(){
		echo basename(MODULE_NAME.ACTION_NAME);	
	}
	public function insert(){
        if(IS_POST){
            $_POST['site_id'] = (int)__SITEID__;
            $_POST['datetime']=strtotime($_POST['date'].$_POST['datehour']);
			$_POST['creator_id']=$this->userInfo['id'];
			$_POST['creator_name']=$this->userInfo['name'];
            $_POST['remark']=strip_tags($_POST['remark']);
			$_POST['rule_id']=implode(',',$_POST['rule_id']);
			
			$memberid=is_array($_POST['memberid'])?$_POST['memberid']:explode(',',$_POST['memberid']);
			foreach($memberid as $va){
				if(''==trim($va)){continue;}
				$_POST['member_id']=(int)$va;
				if(!$this->task->insert()){ $this->error($task->getError());}
			}
			$this->success('插入成功');
        }
	}
	public function getTask(){
		$this->initView();
		$task=new Task();
		$map['site_id']=__SITEID__;
		$map['pid']=isset($_GET['id'])?$_GET['id']:0;
		//$map['datetime']=array('GT',strtotime("-1 month"));
		echo(json_encode($task->selectall($map)));
	}
	public function getInfo(){
		if($_GET['id']){
			$task=new Task($_GET['id']);
			echo(json_encode(['statu'=>1,'info'=>$task->getInfo()]));
		}
	}
	public function update(){
		if($this->_get('id')){
            $_POST['id']=$this->_get('id');
			$_POST['time']=strtotime($_POST['date']);
			if(!$this->task->update()){
				$this->error($this->task->getError());
			}else{
				$this->success('插入成功');
			};
		}
	}
	public function delete(){
		if($this->_get('id')){
			if(!$this->task->delete($this->_get('id'))){
				$this->error($this->task->getError());
			}else{
				$this->success('插入成功');
			};
		}
	}
	
}

